@extends('Admin.layout.layout')
@section('content')
    <div class="row">
        <div class="col-lg-12">
            <h1 class="page-header">公告列表</h1>
        </div>
        <!-- /.col-lg-12 -->
    </div>

<div class="row">
<!-- ==========提示框=========== -->
<div id="messagesuccess" class="alert alert-info" style="display:none">
    <span></span> 
</div>
<div id="messagedanger" class="alert alert-danger" style="display:none">
    <span></span>
</div>
<div class="col-lg-12">
    <div class="panel panel-default">
        <div class="panel-heading">
            DataTables Advanced Tables
        </div>
        <!-- /.panel-heading -->
        <div class="panel-body">
            <form action="{{url('/admin/notice/index')}}" method="get" >
                <div class="dataTable_wrapper">
                <div id="dataTables-example_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
                <div class="row"><div class="col-sm-6">
                <div class="dataTables_length" id="dataTables-example_length">
                <label>显示<select name="num" aria-controls="dataTables-example" class="form-control input-sm">
                <option value="10" @if(!empty($request['num']) && $request['num'] == 10) { selected } @endif>10</option>
                <option value="25" @if(!empty($request['num']) && $request['num'] == 25) { selected } @endif>25</option>
                <option value="50" @if(!empty($request['num']) && $request['num'] == 50) { selected } @endif>50</option>
                <option value="100" @if(!empty($request['num']) && $request['num'] == 100) { selected } @endif>100</option>
                </select>条</label></div></div>
                <div class="col-sm-6">
                <div id="dataTables-example_filter" class="dataTables_filter">
                <label>作者:<input type="text" name="author" class="form-control input-sm" placeholder="" aria-controls="dataTables-example" value="@if(!empty($request['author'])){{$request['author']}}@endif"><button class="btn btn-success">搜索</button></label></div></div></div>
                </form>   
                </div></div></div>      
                <div class="row">
                <div class="col-sm-12">
                <table class="table table-striped table-bordered table-hover dataTable no-footer" id="dataTables-example" role="grid" aria-describedby="dataTables-example_info">
                    <thead>
                        <tr role="row">
                        <th class="sorting_asc" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-sort="ascending" aria-label="Rendering engine: activate to sort column descending" style="width: 172px;">编号</th>
                        <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="Browser: activate to sort column ascending" style="width: 204px;">公告标题</th>
                        <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="Engine version: activate to sort column ascending" style="width: 149px;">公告时间</th>
                        <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="CSS grade: activate to sort column ascending" style="width: 110px;">公告作者</th>
                        <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="CSS grade: activate to sort column ascending" style="width: 110px;">状态</th>
                        <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="CSS grade: activate to sort column ascending" style="width: 110px;">操作</th></tr>
                    </thead>
                    <tbody>
                        @foreach($notice as $k=>$v)
                        <tr class="gradeA odd" role="row">
                                <td class="sid">{{$v->id}}</td>
                                <td>{{$v->title}}</td>
                                <td class="center">{{$v->time}}</td>
                                <td class="center">{{$v->author}}</td>
                                <td class="center">{{ str_replace(['1','2'],['未使用','使用中'],$v->status)}}</td>
                                <td class="center">
                                <button class=" fa fa-trash-o btn-danger delete">删除</button>
                                <a href="{{url('/admin/notice/edit',['id'=>$v->id])}}"><button class="fa fa-gear btn-info">修改</button></a></td>
                            </tr>
                        @endforeach 
                    </tbody>
                </table>
                <div class="col-sm-12 col-sm-offset-8">
                {!!$notice->appends($request)->render()!!}
                </div>
                </div>
                </div>
            </div>
        </div>
        <!-- /.panel-body -->
    </div>
    <!-- /.panel -->
</div>
<!-- /.col-lg-12 -->
</div>
@endsection

@section('myjs')
    <script type="text/javascript">
    $('.delete').click(function(){
        var id = $(this).parents('tr').find('.sid').html();
        var dd = $(this);
        //设置全局信息
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });
        //发送ajax
        $.post("{{url('/admin/notice/delete')}}",{id:id},function(data){
            if(data == 1){
                dd.parents('tr').remove();
                message('success','删除成功');
            }else{
                message('error','删除失败');
            }
        });
        return false;
    })
            //封装函数显示信息
    function message(er,m)
    {
      if(er == 'success'){
        $('#messagesuccess').find('span').html(m);
        $('#messagesuccess').show();
        setTimeout("$('#messagesuccess').hide()",5000);
      }else{
        $('#messagedanger').find('span').html(m);
        $('#messagedanger').show();
        setTimeout("$('#messagedanger').hide()",5000);

      }
    }
    </script>
@endsection